package com.domain.service.impl;

import com.domain.common.Result;
import com.domain.dao.BillMapper;
import com.domain.pojo.Bill;
import com.domain.service.BillService;
import com.domain.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;

@Service
@Transactional(rollbackFor = Exception.class)
public class BillServiceImpl implements BillService {

    @Autowired
    private BillMapper billMapper;

    /**
     * 添加账单
     *
     * @param userId
     * @param detail
     * @param billType
     * @param money
     * @param billIcons
     * @return
     */
    public Result addBill(String orderNum, String userId, String detail, String billType, String money, String billIcons) {
        Bill b = new Bill();
        b.setId(UUIDUtils.getRandomUUID());
        b.setBillMoney(new BigDecimal(money));
        b.setBillDetail(detail);
        b.setBillType(billType);
        b.setBillTime(new Date());
        b.setWalletId(userId);
        b.setSpareOne(billIcons);
        b.setSpareTwo(orderNum);
        billMapper.insertSelective(b);
        return Result.success();
    }
}
